import React, { useState } from 'react';
import {
  DesktopOutlined,
  FileOutlined,
  PieChartOutlined,
  TeamOutlined,
  UserOutlined,
} from '@ant-design/icons';
import type { MenuProps } from 'antd';
import { Breadcrumb, Layout, Menu, theme } from 'antd';
import {useNavigate,Outlet} from 'react-router-dom'

const { Header, Content, Footer, Sider } = Layout;

type MenuItem = Required<MenuProps>['items'][number];

function getItem(
  label: React.ReactNode,
  key: React.Key,
  icon?: React.ReactNode,
  children?: MenuItem[],
): MenuItem {
  return {
    key,
    icon,
    children,
    label,
  } as MenuItem;
}

const items: MenuItem[] = [
  getItem('栏目一', '/page1', <PieChartOutlined />),
  getItem('栏目二', '/page2', <DesktopOutlined />),
  getItem('User', 'sub1', <UserOutlined />, [
    getItem('Tom', '3'),
    getItem('Bill', '4'),
    getItem('Alex', '5'),
  ]),
  getItem('Team', 'sub2', <TeamOutlined />, [getItem('Team 1', '6'), getItem('Team 2', '8')]),
  getItem('Files', '9', <FileOutlined />),
];

const View: React.FC = () => {
  const [collapsed, setCollapsed] = useState(false);

  const navigateTo = useNavigate()

  const {
    token: {  borderRadiusLG },
  } = theme.useToken();

  const MenuClick = (e: any) => {
    console.log('click ', e.key);
    //点击跳转到对应路由  编程式导航
    navigateTo(e.key)
  }

  return (
    <Layout style={{ minHeight: '100vh' }}>
      <Sider collapsible collapsed={collapsed} onCollapse={(value) => setCollapsed(value)}>
        <div className="demo-logo-vertical" style={{height:'32px',margin:'16px',background:'rgba(255,255,255,0.3)'}} />
        <Menu theme="dark" defaultSelectedKeys={['1']} mode="inline" items={items} onClick={MenuClick}/>
      </Sider>
      <Layout>
        <Header style={{ padding: 0, background: "#eee" }} >
        <Breadcrumb style={{lineHeight:'64px',paddingLeft:'16px'}} items={[
            {title:'Home'},
            {title:'List'},
          ]}>
        </Breadcrumb>
        </Header>
        <Content style={{ margin: '16px  16px' }}>
        
          <div
            style={{
              padding: 24,
              minHeight: '100%',
              background: '#eee',
              borderRadius: borderRadiusLG,
            }}
          >
            {/* 窗口部分 */}
<Outlet/>
          </div>
        </Content>
        <Footer style={{ textAlign: 'center' ,padding:0,lineHeight:'48px'}}>
          Ant Design ©{new Date().getFullYear()} Created by Ant UED
        </Footer>
      </Layout>
    </Layout>
  );
};

export default View;